var changeFormValidator = null;
var changeForm = null;
var targetId = null;
$(document).ready(function() {  
	
	$('#changePasswordLi a').live('click', function (e) {
		
		$("#password").focus();
		$('#changePwdModal').modal({
	        show: 'true'
	    });
	});
	
	changeForm = $("#changePwdFrm");
	changeFormValidator = changeForm.validate({
		rules: {
			
			"oldPassword": {
				required: true,
				rangelength: [5, 16]
			},
			
			"newPassword": {
				required: true,
				rangelength: [5, 16]
			},
			
			"confirmPassword": {
				required: true,
				rangelength: [5, 16],
				equalTo:"#newPassword"
			},
			
		},
		
		messages: {
			
			"oldPassword": {
				required: "请输入旧密码",
				rangelength: jQuery.format("密码长度 {0}~{1} 个字符")
			},
			
			"newPassword": {
				required: "请输入新密码",
				rangelength: jQuery.format("密码长度 {0}~{1} 个字符")
			},
			
			"confirmPassword": {
				required: "请再次输入新密码",
				rangelength: jQuery.format("密码长度 {0}~{1} 个字符"),
				equalTo:"两次输入密码不一致"
			},
		},
		errorElement: 'span', //default input error message container
	    errorClass: 'help-block margin_100', // default input error message class
	    focusInvalid: false, // do not focus the last invalid input
	    ignore: "",
		success: function (label) {
	         label.closest('.input-group').removeClass('has-error'); // set success class to the control group
	         label.remove();
	     },
	     
	     highlight: function (element) {
        	$(element).closest('.input-group').addClass('has-error');
        },
        
        unhighlight: function (element) {
        	$(element).closest('.input-group').removeClass('has-error');
        },
        
        errorPlacement: function (error, element) {
        	$(element).after(error);
        },
        
        invalidHandler: function (event, validator) { //display error alert on form submit              
            App.scrollTo($(this), -200);
        }
		
	});
	
	
});

function closeChangeModal() {
	changeFormValidator.resetForm();
	changeForm[0].reset();
	$(".input-group ").removeClass('has-error');
	$("#changePwdModal .close").click();
}



